package com.cmict.data.bpm.controller.admin.definition;

import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.bpm.controller.admin.definition.vo.task.TaskVariableCreateReqVO;
import com.cmict.data.bpm.controller.admin.definition.vo.task.TaskVariableUpdateReqVO;
import com.cmict.data.bpm.service.definition.TaskVariableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.cmict.data.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 流程变量")
@RestController
@RequestMapping("/bpm/task-variable")
@Validated
public class TaskVariableController {

    @Resource
    private TaskVariableService taskVariableService;

    @PostMapping("/create")
    @ApiOperation("创建流程变量")
    @PreAuthorize("@ss.hasPermission('bpm:task-variable:create')")
    public CommonResult<Long> createTaskVariable(@Valid @RequestBody TaskVariableCreateReqVO createReqVO) {
        return success(taskVariableService.createTaskVariable(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新流程变量")
    @PreAuthorize("@ss.hasPermission('bpm:task-variable:update')")
    public CommonResult<Boolean> updateTaskVariable(@Valid @RequestBody TaskVariableUpdateReqVO updateReqVO) {
        taskVariableService.updateTaskVariable(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除流程变量")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('bpm:task-variable:delete')")
    public CommonResult<Boolean> deleteTaskVariable(@RequestParam("id") Long id) {
        taskVariableService.deleteTaskVariable(id);
        return success(true);
    }

//    @GetMapping("/get")
//    @ApiOperation("获得流程变量")
//    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
//    @PreAuthorize("@ss.hasPermission('bpm:task-variable:query')")
//    public CommonResult<TaskVariableRespVO> getTaskVariable(@RequestParam("id") Long id) {
//        TaskVariableDO taskVariable = taskVariableService.getTaskVariable(id);
//        return success(TaskVariableConvert.INSTANCE.convert(taskVariable));
//    }
//
//    @GetMapping("/list")
//    @ApiOperation("获得流程变量列表")
//    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('bpm:task-variable:query')")
//    public CommonResult<List<TaskVariableRespVO>> getTaskVariableList(@RequestParam("ids") Collection<Long> ids) {
//        List<TaskVariableDO> list = taskVariableService.getTaskVariableList(ids);
//        return success(TaskVariableConvert.INSTANCE.convertList(list));
//    }
//
//    @GetMapping("/page")
//    @ApiOperation("获得流程变量分页")
//    @PreAuthorize("@ss.hasPermission('bpm:task-variable:query')")
//    public CommonResult<PageResult<TaskVariableRespVO>> getTaskVariablePage(@Valid TaskVariablePageReqVO pageVO) {
//        PageResult<TaskVariableDO> pageResult = taskVariableService.getTaskVariablePage(pageVO);
//        return success(TaskVariableConvert.INSTANCE.convertPage(pageResult));
//    }

}
